package config

import "sync"

const ROOT_PATH_DEFAULT = "/data/tinydocker"

var (
	globalConfig *Config
	once         sync.Once
)

type Config struct {
	RootPath      string
	ContainerPath string
	ImagePath     string
	CommonLogPath string
	NetworkDir    string // 网络相关配置目录
}

func initConfig() {
	once.Do(func() {
		// 读取配置文件 比如 /etc/tindydocker/config.json 可以通过 -c 传入
		globalConfig = &Config{
			RootPath:      ROOT_PATH_DEFAULT, // @todo 稍后改为依赖命令行传入
			ContainerPath: ROOT_PATH_DEFAULT + "/container",
			ImagePath:     ROOT_PATH_DEFAULT + "/image",
			CommonLogPath: ROOT_PATH_DEFAULT + "/tinydocker.log",
			NetworkDir:    ROOT_PATH_DEFAULT + "/network",
		}
	})
}

func GlobalConfig() *Config {
	initConfig()
	return globalConfig
}
